from flask import Blueprint, session, request, url_for, redirect

# 创建蓝图对象
admin_blu = Blueprint("admin", __name__)

from . import views


@admin_blu.before_request
def check_admin():
    is_admin = session.get('is_admin', False)
    # 如果不是管理员,直接跳转到首页 '/admin/login'
    if not is_admin and not request.url.endswith(url_for('admin.login')):
        return redirect('/')
